package com.oceansoft.mobile.econsole.modules.api.service.impl;

import com.oceansoft.mobile.econsole.exam.entity.ExamTest;
import com.oceansoft.mobile.econsole.exam.entity.Option;
import com.oceansoft.mobile.econsole.exam.entity.Questions;
import com.oceansoft.mobile.econsole.exam.entity.QuestionsExt;
import com.oceansoft.mobile.econsole.exam.persistence.IExamMapper;
import com.oceansoft.mobile.econsole.modules.api.service.IDoExamService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by liujie on 2016/8/22.
 */
@Service
public class DoExamServiceImpl implements IDoExamService {
    @Resource
    IExamMapper examMapper;

    @Override
    public List<QuestionsExt> getQuestionsForAExam(ExamTest exam) {
        long l1 = System.currentTimeMillis();
        List<QuestionsExt> list = examMapper.findQuestionForOneExam(exam);
        for (int i = 0; i < list.size(); i++) {
            QuestionsExt questionsExt = list.get(i);
            List<Option> optionList = examMapper.findOptionByQuestionId(questionsExt.getId());
            if ("1".equals(questionsExt.getIsoptionimg())) {
                for (int j = 0; j < optionList.size(); j++) {
                    Option option = optionList.get(j);
                    option.setAttach(examMapper.findAttachByIdNoContent(option.getId(), "2"));
                }
            }
            questionsExt.setOptions(optionList);
            if ("1".equals(questionsExt.getIsimg())) {
                questionsExt.setAttach(examMapper.findAttachByIdNoContent(questionsExt.getId(), "1"));
            }
        }
        long l2 = System.currentTimeMillis();
        System.out.println("取题耗时：" + (l2 - l1));

        return list;
    }
}
